package com.ruoyi.teacher.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.SxTeachers;
import com.ruoyi.teacher.service.ISxTeachersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师信息Controller
 * 
 * @author ruoyi
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/teacher/teachers")
public class SxTeachersController extends BaseController
{
    @Autowired
    private ISxTeachersService sxTeachersService;

    /**
     * 查询教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:teachers:list')")
    @GetMapping("/list")
    public TableDataInfo list(SxTeachers sxTeachers)
    {
        startPage();
        List<SxTeachers> list = sxTeachersService.selectSxTeachersList(sxTeachers);
        return getDataTable(list);
    }

    /**
     * 导出教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:teachers:export')")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SxTeachers sxTeachers)
    {
        List<SxTeachers> list = sxTeachersService.selectSxTeachersList(sxTeachers);
        ExcelUtil<SxTeachers> util = new ExcelUtil<SxTeachers>(SxTeachers.class);
        util.exportExcel(response, list, "教师信息数据");
    }

    /**
     * 获取教师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:teachers:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
    {
        return success(sxTeachersService.selectSxTeachersByTeacherId(teacherId));
    }

    /**
     * 新增教师信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:teachers:add')")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SxTeachers sxTeachers)
    {
        return toAjax(sxTeachersService.insertSxTeachers(sxTeachers));
    }

    /**
     * 修改教师信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:teachers:edit')")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SxTeachers sxTeachers)
    {
        return toAjax(sxTeachersService.updateSxTeachers(sxTeachers));
    }

    /**
     * 删除教师信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:teachers:remove')")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(sxTeachersService.deleteSxTeachersByTeacherIds(teacherIds));
    }
}
